package com.coding.kan_yi_dao.controller;


import cn.hutool.core.util.RandomUtil;
import com.coding.kan_yi_dao.common.Result;
import com.coding.kan_yi_dao.entity.GoodsOrder;
import com.coding.kan_yi_dao.entity.User;
import com.coding.kan_yi_dao.service.impl.GoodsOrderServiceImpl;
import com.coding.kan_yi_dao.service.impl.UserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 砍一刀，不买就砍你一刀
 * @since 2023-09-20
 */
@Api(tags = "订单配置")
@RestController
@RequestMapping("/goods_order")
@CrossOrigin
public class GoodsOrderController {

    @Resource
    GoodsOrderServiceImpl goodsOrderService;

    @Resource
    UserServiceImpl userService;

    //TODO 查询
    @ApiOperation(value = "全查询")
    @GetMapping("/go_select/order")
    public Result go_select() {
        return goodsOrderService.go_select();
    }

    //TODO 修改
    @ApiOperation(value = "修改")
    @GetMapping("/go_update/order")
    public Result go_update(GoodsOrder goodsOrder, User user) {
        if (user.getUserId() == null) {
            return goodsOrderService.go_update(goodsOrder);
        }
        userService.go_updatess(user);
        return goodsOrderService.go_update(goodsOrder);
    }

    //TODO 配货完成
    @ApiOperation(value = "配货完成")
    @GetMapping("/go_update/order/shop")
    public Result go_update_order(@RequestParam(value = "ids", required = false) List<Integer> ids) {
        return goodsOrderService.go_update_shop(ids);
    }

    //TODO 出库
    @ApiOperation(value = "出库")
    @GetMapping("/go_update/order/ck")
    public Result go_update_ck(@RequestParam(value = "ids", required = false) List<Integer> ids) {
        return goodsOrderService.go_update_ck(ids);
    }

    //TODO 批量删除
    @ApiOperation(value = "批量删除")
    @GetMapping("/go_deleteall/order")
    public Result go_deleteall(@RequestParam(value = "ids", required = false) List<Integer> ids) {
        return goodsOrderService.go_deleteall(ids);
    }

    //TODO 添加
    @ApiOperation(value = "订单添加")
    @GetMapping("/go_insert/order")
    public Result go_insert(GoodsOrder goodsOrder,@RequestParam(value="ids",required=false)  List<Integer> ids,@RequestParam(value="counts",required=false)  List<Integer> counts) {
        return goodsOrderService.go_insert(goodsOrder,ids,counts);
    }
    //TODO 查询
    @ApiOperation(value = "前台订单查询")
    @GetMapping("/go_select/order/item")
    public Result go_selects(Integer user_id) {
        return goodsOrderService.go_order_item(user_id);
    }


}
